package com.ysqcould.web.controller.approval;


import com.ysqcould.approval.domain.Conference;
import com.ysqcould.approval.domain.vo.ConferenceVo;
import com.ysqcould.approval.service.IConferenceService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/approval/conference")
public class ConferenceController extends BaseController
{
    @Autowired
    private IConferenceService conferenceService;

    /**
     * 查询会议列表
     */
    @PreAuthorize("@ss.hasPermi('approval:conference:list')")
    @GetMapping("/list")
    public TableDataInfo list(Conference conference)
    {
        startPage();
        List<ConferenceVo> list = conferenceService.selectConferenceList(conference);
        return getDataTable(list);
    }

    /**
     * 导出会议列表
     */
    @PreAuthorize("@ss.hasPermi('approval:conference:export')")
    @Log(title = "会议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Conference conference)
    {
        List<ConferenceVo> list = conferenceService.selectConferenceList(conference);
        ExcelUtil<ConferenceVo> util = new ExcelUtil<ConferenceVo>(ConferenceVo.class);
        util.exportExcel(response, list, "会议数据");
    }

    /**
     * 获取会议详细信息
     */
    @PreAuthorize("@ss.hasPermi('approval:conference:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(conferenceService.selectConferenceById(id));
    }

    /**
     * 新增会议
     */
    @PreAuthorize("@ss.hasPermi('approval:conference:add')")
    @Log(title = "会议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Conference conference)
    {
        conference.setAsId(getUserId());
        return toAjax(conferenceService.insertConference(conference));
    }

    /**
     * 修改会议
     */
    @PreAuthorize("@ss.hasPermi('approval:conference:edit')")
    @Log(title = "会议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Conference conference)
    {
        return toAjax(conferenceService.updateConference(conference));
    }

    /**
     * 删除会议
     */
    @PreAuthorize("@ss.hasPermi('approval:conference:remove')")
    @Log(title = "会议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(conferenceService.deleteConferenceByIds(ids));
    }
}
